<?php 
/**
 *  urlRewrite操作类
 *
 * @copyright	http://www.easymvc.com
 * @author 		Ron  modify by 光哥 <439884988@qq.com>
 * @version		1.0 - 2012-02-01
 * @package		Lib
 */

if(!defined('EASYMVC')) {
	exit('Access Denied');
}
/**
 * 2种 url 规则 ，path 和普通
 */
class Lib_Url {
	
	
	public  static function rewriteUrl($string){
		if(!$string) return Frame_Config::get('config.url');
		switch(URL_RULE) {
			case 'path': return self::urlPath($string);
			break;
			default : return self::urlNormal($string);
		}
	}
	
	
	public static function urlNormal($string){
		$domain = Frame_Config::get('config.domain');
		$url = Frame_Config::get('config.url');
		
		
		@list($app,$d,$f) = explode('/',$string);
		if($f) {
		}else{
			$f = $d ? $d : 'index';
			$d = '';
		}
		
		if(ALIAS){
			$rewriteUrl = 'http://'.$app.'.'.$domain.'/'."index.php?";
		}else {
		    
			$rewriteUrl = $url."index.php?app=$app";
		}
		
		if($d) $rewriteUrl .= "&d=$d";
		if($f) $rewriteUrl .= "&f=$f";
		
		return $rewriteUrl;
		
	}
	public static function urlPath($string){

		$domain = Frame_Config::get('config.domain');
		$url = Frame_Config::get('config.url');
		
		$arr = explode('/', $string);
		$rewriteUrl = '';
		
		$count = count($arr);
		
		if(ALIAS){
			for($i=0;$i<$count;$i++){
				if($i == 0) {
					
						$rewriteUrl  = 'http://'. $arr[0] .'.'.$domain;
					
				}else {
					$rewriteUrl  .= '/'.$arr[$i];
				}
			}
		
		} else {
				
			$rewriteUrl = $url . str_replace('www/','',$string);
		}
		return $rewriteUrl;
	}
	
}

?>